﻿using D.UtilCore;
using D.UtilCore.Dtos;
using D.UtilCore.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using CozeDto.ProjectInstanceDtos;
using CozeDomain.IServices;
using D.UtilFreesqlOrm;

namespace CozeWebApi
{
    /// <summary>
    /// 站点所属项目模块
    /// </summary>
    [Route("/api/[controller]/[action]")]
    [Authorize]
    public class ProjectInstanceController : BaseApiController
    {
        private readonly IProjectInstanceService _projectInstanceService;
        public ProjectInstanceController(IProjectInstanceService projectInstanceService)
        {
            _projectInstanceService = projectInstanceService;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="reqAddProjectInstance"></param>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        [UnitOfWork]
        public async Task<ApiResult<int>> Add([FromBody] ReqAddProjectInstance reqAddProjectInstance)
        {
            reqAddProjectInstance.CreateUser = Account;
            return await _projectInstanceService.AddProjectInstanceAsync(reqAddProjectInstance);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="tenantId"></param>
        /// <returns></returns>
        [HttpGet("{tenantId}"), TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<RepProjectList>> List(string? tenantId)
        {
            return await _projectInstanceService.QueryProjectListByTenantIdAsync(tenantId);
        }


        /// <summary>
        /// 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost, TypeFilter(typeof(ExtActionFilterAttribute))]
        [Authorize]
        public async Task<ApiResult<PageModel<RepProjectInstanceInfo>>> Pages([FromBody] ReqQueryProjectInstancePage reqQueryProjectInstancePage)
        {
            return await _projectInstanceService.QueryProjectInstancePagesAsync(reqQueryProjectInstancePage);
        }
    }
}
